import { KeyEventParameters, DirectionCode, SceneUtils } from "../../SceneControl";
import HandGridMoveScene from "../HandGridMoveScene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class BattleViewScene extends HandGridMoveScene {

    protected onEnable(): void {
        super.onEnable();
        this.onBack = cc.find("battle/ui/btnPause", this.node);
    }

    protected addBtnEventKeyDown(para: KeyEventParameters): void {
        if (para.DirectionCode === DirectionCode.ENTER) {
            const btn: cc.Node = this.nodeGrid[this.currSite.x][this.currSite.y];
            const item = this.items.find(item => item._view === btn);
            if (item) {
                if (!item.isDraging && item.data && btn.hasEventListener(cc.Node.EventType.TOUCH_START)) {
                    this.catchNode = btn;
                }
            } else if (this.buttons.includes(btn)) {
                SceneUtils.emitButton(btn);
            } else if (btn.hasEventListener(cc.Node.EventType.TOUCH_START)) {
                SceneUtils.emitButton(btn);
            }
        }
    }
}
